//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.framework.seedkit.utils.encrypt;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

public class HexUtil {
    public static boolean ultrafast = false;
    public static boolean useAsyncQueue = true;
    public static boolean commitWhenFailed = false;
    public static int peekMinInterval = 200;
    public static String[] byteHexTable = new String[]{"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0A", "0B", "0C", "0D", "0E", "0F", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B", "1C", "1D", "1E", "1F", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", "2F", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3A", "3B", "3C", "3D", "3E", "3F", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5A", "5B", "5C", "5D", "5E", "5F", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", "7B", "7C", "7D", "7E", "7F", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8A", "8B", "8C", "8D", "8E", "8F", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9A", "9B", "9C", "9D", "9E", "9F", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB", "AC", "AD", "AE", "AF", "B0", "B1", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "BA", "BB", "BC", "BD", "BE", "BF", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "CA", "CB", "CC", "CD", "CE", "CF", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "DA", "DB", "DC", "DD", "DE", "DF", "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "EB", "EC", "ED", "EE", "EF", "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "FA", "FB", "FC", "FD", "FE", "FF"};

    public HexUtil() {
    }

    public static String ByteBufferGetString(ByteBuffer b, int n) {
        byte[] ba = new byte[n];
        b.get(ba, 0, n);
        return new String(ba);
    }

    public static String hex(byte[] dst) {
        StringBuffer sb = new StringBuffer();

        for(int i = 0; i < dst.length; ++i) {
            sb.append(byteHexTable[dst[i] & 255]);
        }

        return sb.toString();
    }

    public static String hex(byte b) {
        return byteHexTable[b & 255];
    }

    public static String hex(int b) {
        return byteHexTable[b & 255];
    }

    public static String hex(byte[] dst, boolean sp) {
        if(ultrafast) {
            return "";
        } else {
            StringBuffer sb = new StringBuffer();

            for(int j = 0; j < dst.length; j += 16) {
                int i;
                for(i = j; i < j + 16; ++i) {
                    if((i & 7) == 0) {
                        sb.append(' ');
                    }

                    if(i < dst.length) {
                        sb.append(byteHexTable[dst[i] & 255]);
                    } else {
                        sb.append("  ");
                    }

                    sb.append(' ');
                }

                for(i = j; i < j + 16; ++i) {
                    if((i & 7) == 0) {
                        sb.append(' ');
                    }

                    if(i < dst.length) {
                        sb.append(printableChar(dst[i]));
                    } else {
                        sb.append(" ");
                    }
                }

                sb.append('\n');
            }

            return sb.toString();
        }
    }

    private static char printableChar(byte b) {
        return b >= 32 && b < 127?(char)b:'.';
    }

    public static byte[] join(byte[] b1, byte[] b2) {
        byte[] out = new byte[b1.length + b2.length];
        ByteBuffer.wrap(out).put(b1).put(b2);
        return out;
    }

    public static List createList() {
        return Collections.synchronizedList(new LinkedList());
    }

    public static String ByteBufferGetLine(ByteBuffer in, char c) {
        byte[] ba = new byte[in.remaining()];

        for(int i = 0; in.remaining() > 0; ++i) {
            byte b = in.get();
            if(b == c) {
                return new String(ba, 0, i);
            }

            ba[i] = b;
        }

        return null;
    }

    public static byte[] ByteBufferGetByteArray(ByteBuffer in, int n) {
        byte[] ba = new byte[n];
        in.get(ba, 0, n);
        return ba;
    }

    private static byte h2b(byte c) {
        return c <= 57 && c >= 48?(byte)(c - 48):(c >= 97 && c <= 122?(byte)(c - 97 + 10):(byte)(c - 65 + 10));
    }

    public static byte[] unhexba(String ss) {
        ss = ss.replaceAll(" ", "");
        if(ss.length() % 2 != 0) {
            ss = "0" + ss;
        }

        byte[] ba1 = ss.getBytes();
        byte[] ba = new byte[ss.length() / 2];

        for(int i = 0; i < ss.length(); i += 2) {
            ba[i / 2] = (byte)(h2b(ba1[i]) * 16 + h2b(ba1[i + 1]));
        }

        return ba;
    }

    public static String[] cutStringBy(String s, int size) {
        Vector v = new Vector();
        byte[] ba = s.getBytes();
        int n = 0;
        int offset = 0;

        while(n < ba.length) {
            int n1 = n;
            n += (ba[n] & 128) != 0?2:1;
            if(n - offset >= size) {
                if(n - offset > size) {
                    n = n1;
                }

                v.add(new String(ba, offset, n - offset));
                offset = n;
            }
        }

        v.add(new String(ba, offset, n - offset));
        return Vector2ArrayStr(v);
    }

    public static String[] cutStringByCN(String s, int size) {
        Vector v = new Vector();
        byte[] ba = s.getBytes();
        int n = 0;
        int i = 0;
        int offset = 0;

        while(n < ba.length) {
            n += (ba[n] & 128) != 0?2:1;
            ++i;
            if(i >= size) {
                v.add(new String(ba, offset, n - offset));
                offset = n;
                i = 0;
            }
        }

        if(n > offset) {
            v.add(new String(ba, offset, n - offset));
        }

        return Vector2ArrayStr(v);
    }

    private static String[] Vector2ArrayStr(Vector v) {
        String[] ss = new String[v.size()];

        for(int i = 0; i < v.size(); ++i) {
            ss[i] = (String)v.get(i);
        }

        return ss;
    }

    public static void sleep(int wt) {
        try {
            Thread.sleep((long)wt);
        } catch (InterruptedException var2) {
            var2.printStackTrace();
        }

    }

    public static byte[] iobuffer2array(ByteBuffer buf) {
        byte[] x = new byte[buf.position()];
        buf.flip();
        buf.get(x);
        return x;
    }

    public static byte[] IoBufferGetArray(ByteBuffer buf, int n) {
        byte[] ba = new byte[n];
        buf.get(ba);
        return ba;
    }

    public static String iosessionGetStr(ByteBuffer buf, int i) {
        byte x = buf.get();
        if(x + 1 > i) {
            throw new Error("wrong size of : " + x);
        } else {
            byte[] y = new byte[x];
            buf.get(y);

            for(int j = 0; j < i - 1 - x; ++j) {
                buf.get();
            }

            return new String(y);
        }
    }

    public static int min(int i, int j) {
        return i > j?j:i;
    }

    public static byte[] cutBytes(byte[] datas, int nSent, int n) {
        byte[] x = new byte[n];
        System.arraycopy(datas, nSent, x, 0, n);
        return x;
    }

    public static void writeFile(String name, byte[] data) {
        try {
            BufferedOutputStream e = new BufferedOutputStream(new FileOutputStream(name));
            e.write(data);
            e.close();
        } catch (FileNotFoundException var3) {
            var3.printStackTrace();
        } catch (IOException var4) {
            var4.printStackTrace();
        }

    }

    public static void writeFile(String name, String d) {
        writeFile(name, d.getBytes());
    }

    public static byte[] readFile(String name) {
        File f = new File(name);
        byte[] data = new byte[(int)f.length()];

        try {
            (new FileInputStream(name)).read(data);
        } catch (FileNotFoundException var4) {
            var4.printStackTrace();
        } catch (IOException var5) {
            var5.printStackTrace();
        }

        return data;
    }

    public static byte[] readFile(URI u) {
        File f = new File(u);
        byte[] data = new byte[(int)f.length()];

        try {
            (new FileInputStream(f)).read(data);
        } catch (FileNotFoundException var4) {
            var4.printStackTrace();
        } catch (IOException var5) {
            var5.printStackTrace();
        }

        return data;
    }

    public static byte[] ioBufferReadAll(ByteBuffer buf) {
        byte[] x = new byte[buf.remaining()];
        buf.get(x);
        return x;
    }

    public static void waitFileExist(String string) {
        while(true) {
            File f = new File(string);
            if(f.exists()) {
                return;
            }

            sleep(100);
        }
    }

    public static void deleteFile(String string) {
        (new File(string)).delete();
    }

    public static void runAndWait(String string) throws IOException {
        Process x = Runtime.getRuntime().exec("test.bat");

        while(true) {
            try {
                x.waitFor();
                return;
            } catch (InterruptedException var3) {
                var3.printStackTrace();
            }
        }
    }

    public static String pad(String a, String b, int i) {
        if(a == null) {
            for(a = b; a.length() < i; a = a + b) {
                ;
            }
        } else {
            while(a.length() < i) {
                a = a + b;
            }
        }

        return a;
    }

    public static String ascii(String x) {
        return hex(x.getBytes());
    }

    public static byte[] unhexba_1(String ss) {
        byte[] hex = ss.getBytes();
        byte[] bytes = new byte[hex.length / 2];

        for(int i = 0; i < bytes.length; ++i) {
            int v = i * 2;
            int b = Character.digit(hex[v], 16) << 4;
            b |= Character.digit(hex[v + 1], 16);
            bytes[i] = (byte)(b & 255);
        }

        return bytes;
    }

    public static String hex(byte[] dst, String split) {
        StringBuffer sb = new StringBuffer();

        for(int i = 0; i < dst.length; ++i) {
            sb.append(split + byteHexTable[dst[i] & 255]);
        }

        return sb.toString();
    }
}
